# —*— coding: utf-8 -*-

from functools import partial

import py_global
import logging

logger = logging.getLogger(__name__)


def def_args(*args, **kwargs):
    """函数参数"""
    logger.info(f'args size:{len(args)},kwargs length:{len(kwargs)}.')
    logger.info(f'args:{args},kwargs:{kwargs}.')

    kwargs['keyword'] = 'def_args'
    logger.info(f'kwargs:{kwargs}.')
    pass


def def_dict(arg_dict: dict):
    """
    元组参数
    字典参数
    """
    arg_dict['keyword'] = 'def_dict'
    logger.info(f'kwargs:{arg_dict}.')
    pass


def function(argument, callback):
    logger.info('argument=%d', argument)
    callback()
    pass


def closure():
    """闭包closure"""
    variable = 1
    argument = 2

    def callback():
        logger.info('variable=%d', variable)
        pass

    # 回调函数作为参数
    function(argument, callback)

    def func(arg0, arg1):
        logger.info('arg0=%d,agr1=%d.', arg0, arg1)
        pass

    function(argument, lambda: func(3, 4))
    function(argument, partial(func, 3, 4))


if __name__ == '__main__':
    args_tuple: tuple = (1, 2, 3)
    kwargs_dict: dict = {'key': 'value'}
    def_args(1, *args_tuple, k='v', **kwargs_dict)

    def_dict(kwargs_dict)
    logger.info(f'kwargs_dict:{kwargs_dict}')

    # instance = locals()['function']
    # instance()

    # closure()

    pass
